//
//  LJWelcomeView.swift
//  LJWeibo
//
//  Created by 连俊杨 on 2017/10/24.
//  Copyright © 2017年 yang_ljun. All rights reserved.
//

import UIKit
import SDWebImage

class LJWelcomeView: UIView {
    
    @IBOutlet weak var iconView: UIImageView!
    @IBOutlet weak var tipLabel: UILabel!
    @IBOutlet weak var bottomCons: NSLayoutConstraint!
    
    /// 类初始化方法，从xib加载本类
    class func welcomeView() -> LJWelcomeView {
        let nib = UINib(nibName: "LJWelcomeView", bundle: nil)
        let view = nib.instantiate(withOwner: nil, options: nil)[0] as? LJWelcomeView
        
        view?.frame = UIScreen.main.bounds
        
        return view!
    }
    
    override func awakeFromNib() {
        
        guard let urlString = LJNetworkManager.sharedManager.userAccount.avatar_large,
            let url = URL(string: urlString) else {
            return
        }
        
        iconView.sd_setImage(with: url, placeholderImage: UIImage(named: "avatar_default_big"))
        
        /// 圆形头像
        iconView.layer.cornerRadius = iconView.bounds.width * 0.5
        iconView.layer.masksToBounds = true
    }
    
    /// 做动画处理
    /// 视图被添加到 window上，表示视图已经显示
    override func didMoveToWindow() {
        super.didMoveToWindow()
        layoutIfNeeded()
        
        bottomCons.constant = bounds.height - 200
        
        UIView.animate(withDuration: 1.5,
                       delay: 0,
                       usingSpringWithDamping: 0.7,
                       initialSpringVelocity: 0,
                       options: [],
                       animations: { 
                        self.layoutIfNeeded()
        }) { (_) in
            UIView.animate(withDuration: 1.0, animations: { 
                self.tipLabel.alpha = 1
            }, completion: { (_) in
                self.removeFromSuperview()
            })
        }
    }
}






